<template>
  <div>
    <el-breadcrumb
      separator="/"
      style="padiding-left: 10px; padding-bottom: 10px; font-size: 12px"
    >
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="部门" label-width="70px">
          <el-select clearable v-model="formInline.city" placeholder="请选择">
            <el-option
              v-for="item in cities"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
              <span style="float: left">{{ item.label }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{
                item.value
              }}</span>
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="用户名" label-width="70px">
          <el-input
            clearable
            v-model="formInline.user"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>

        <el-form-item label="邮箱" label-width="70px">
          <el-input
            clearable
            v-model="formInline.email"
            placeholder="请输入邮箱"
          ></el-input>
        </el-form-item>

        <el-form-item label-width="70px">
          <el-radio v-model="formInline.radio" label="1">备选项</el-radio>
          <el-radio v-model="formInline.radio" label="2">备选项</el-radio>
          <el-radio v-model="formInline.radio" label="3">备选项</el-radio>
        </el-form-item>

        <el-form-item label="昵称" label-width="70px">
          <el-input
            clearable
            v-model="formInline.nikeName"
            placeholder="请输入昵称"
          ></el-input>
        </el-form-item>

        <el-form-item label-width="70px" style="margin-left: 30px">
          <el-button icon="el-icon-refresh">重置</el-button>
          <el-button type="primary" icon="el-icon-search">查询</el-button>
          <el-button type="success" icon="el-icon-plus">添加</el-button>
          <el-button type="warning" icon="el-icon-download">导出</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="userList" border style="width: 100%;" max-height="500">
        <el-table-column prop="id" label="#" width="50"></el-table-column>
        <el-table-column prop="username" label="用户名" width="120"></el-table-column>
        <el-table-column prop="sex" label="性别" width="110">
          <template slot-scope="scope">{{scope.row.sex == 0 ? '男':(scope.row.sex == 0 ?'女':'保密')}}</template>
        </el-table-column>
        <el-table-column prop="name" label="所属部门" width="180" sortable></el-table-column>
        <el-table-column prop="birth" label="生日" width="180" sortable></el-table-column>
        <el-table-column prop="email" label="邮箱" width="200" ></el-table-column>
        <el-table-column prop="phoneNumber" label="电话" width="150"></el-table-column>
        <el-table-column prop="status" label="是否禁用" width="100">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status == 1" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <el-button type="primary" size="mini" icon="el-icon-edit"></el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete"></el-button>
          <el-button type="warning" size="mini" icon="el-icon-s-tools"></el-button>
        </el-table-column>
      </el-table>

      <el-pagination
        style="padding-top: 15px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[8, 10, 15,20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import {findUsers} from '../../api/users'

export default {
  data() {
    return {
      formInline: {
        user: "",
        email: "",
        city: "",
        radio: "1",
        nikeName: "",
      },
      obj:{},
      vl:true,
      userList: [],  //用户集合
      deptList: [],  //部门集合
      pageSize: null, //每页显示的条数
      total: null, //总条数
      currentPage4: 4,  // 当前页码
      cities: [
        {
          value: "Beijing",
          label: "北京",
        },
        {
          value: "Shanghai",
          label: "上海",
        },
        {
          value: "Nanjing",
          label: "南京",
        },
        {
          value: "Chengdu",
          label: "成都",
        },
        {
          value: "Shenzhen",
          label: "深圳",
        },
        {
          value: "Guangzhou",
          label: "广州",
        },
      ]
    };
  },

  created(){
    //创建组建的时候调用查询所有用户的方法
    this.getUserList()
  },

  methods: {
    onSubmit() {
      console.log("submit!");
    },

    // 当每页条数改变的时候
    handleSizeChange(val) {
      //将 val 赋值给 size
      this.size = val;
      //重新去后台查询数据
      this.getUserList();
      console.log(`每页 ${val} 条`);
    },

    // 当前页码改变的时候
    handleCurrentChange(val) {
      this.currentPage4 = val
      this.getUserList();
      console.log(`当前页: ${val}`);
    },

    async getUserList(){
      const {data} = await findUsers(this.currentPage4,this.size)
      console.log(data)
      this.obj = data.data
      this.userList = data.data.records
      this.pageSize = this.userList.length
      this.total = this.obj.total
      this.vl = this.userList.status == 1? true:false
    }
    
  },
};
</script>

<style>
</style>
